{{template "admin/public/head.html" .}}
<section>
	<aside>
		{{template "admin/public/nav.html" .}}
	</aside>
	<article>
		<div class="top-title">
			<dl>
				<dt><h1>{{.title}}</h1></dt>
			</dl>
		</div>
		<div class="content">
			<div class="release">
				<dl>
					<dt><i class="iconfont">&#xe649;</i> <b>{{.title}}说明</b><br>
						下方是{{.title}}列表,可以进行添加,修改<br>
						<p>添加新的商品结构时,首先单击添加商品结构,选择上级商品结构,添加完成后,再此编辑添加商品</p>
					</dt>
					<dd><a href="/admin/product/struct_add"><button type="button" class="button">添加商品结构</button></a></dd>
				</dl>
			</div>
			<table class="table">
				<thead>
					<th width="15%">id</th>
					<th width="15%">名称</th>
					<th width="25%">图片</th>
					<!-- <th width="15%">商品结构(上一级)</th> -->
					<th width="15%">操作</th>
				</thead>
				{{range .info}}
				<tr id="{{.id}}">
					<td class="center">{{.id}}</td>
					<td class="">
						<a href="/admin/product/struct_edit?id={{.id}}">{{.name}}</a>
					</td>
					<td class="center">
						{{if .pathname}}<img class="img" src="{{.pathname}}">{{end}}
					</td>
					<!-- <td>
						{{if .supeName}}
						{{.supeName}}
						{{else}}
						商城全部商品
						{{end}}
					</td> -->
					<td class="operation">
						<a href="/admin/product/struct_edit?id={{.id}}">编辑</a><br>
						<a href="/admin/product/struct_imgs?id={{.id}}">编辑展示图</a><br>
						<a class="del" data-id="{{.id}}">删除</a><br>
						<a 
							class="change" 
							data-id="{{.id}}" 
							data-status="type"
							href="javascript: void(0)"
						>{{if eq .type "0"}}商品展示{{else}}橱窗展示{{end}}</a><br>
						<a class="import-exl" style="position: relative;">
							导入产品
							<input type="file" style="position: absolute;top: 0;left: 0;height: 100%;width: 100%;opacity: 0;" id="{{.id}}" onchange="xlsxUpload(this)" accept=".xlsx">
						</a><br>
						<a class="export-exl" data-id="{{.id}}">导出产品</a>
					</td>
				</tr>
				{{end}}
				{{if ne .paginator.totalpages 1}}
					<tr>
						<td  colspan="5">
							<div class="paging">
								{{if ne .paginator.currpage 1}}
								<a href="{{$.url}}page={{.paginator.firstpage}}">首页</a>
								<a href="{{$.url}}page={{.paginator.prevpage}}">&lt;&lt;</a>
								{{else}}
								<a class="disable">首页</a>
								<a class="disable">&lt;&lt;</a>
								{{end}}
								{{range $index,$page := .paginator.pages}}
								{{if eq $.paginator.currpage $page}} 
								<a class="no">{{$page}}</a>
								{{else}}
								<a href="{{$.url}}page={{$page}}">{{$page}}</a>
								{{end}}
								{{end}}
								{{if eq .paginator.currpage .paginator.totalpages}}
								<a class="disable">&gt;&gt;</a>
								<a class="disable">尾页</a>
								{{else}}
								<a href="{{$.url}}page={{.paginator.nextpage}}">&gt;&gt;</a>
								<a href="{{$.url}}page={{.paginator.totalpages}}">尾页</a>
								{{end}}
							</div>
						</td>
					</tr>
				{{end}}
			</table>
		</div>
	</article>
</section>

<footer><!-- 系统监控内容 --></footer>
<script src="https://tcsc.oss-cn-hangzhou.aliyuncs.com/static/admin/js/jquery.jedate.min.js"></script>
<script src="https://tcsc.oss-cn-hangzhou.aliyuncs.com/static/admin/js/toast.js"></script>
<script src="https://tcsc.oss-cn-hangzhou.aliyuncs.com/static/admin/js/uppic.js"></script>
<script src="https://tcsc.oss-cn-hangzhou.aliyuncs.com/static/admin/js/xcConfirm.js"></script>
<script src="https://tcsc.oss-cn-hangzhou.aliyuncs.com/static/admin/js/app.js"></script>
<script>
	$('.del').click(function(){
		var id=$(this).attr('data-id');
		wxc.xcConfirm("您确定要删除这条数据吗?","confirm",{onOk:function(){
			$.ajax({
				url:'/admin/del',
				data:{table:'mt_goods_struct',id:id},
				type:'get',
				success:function(res) {
					if(res==1){
						showMessage('删除成功');
						$('#'+id).css('display','none');
					}else{
						wxc.xcConfirm("操作失败,请重试","error");
					}
				}
			})	
		}});
	})
	$('.change').click(function(){
		var id=$(this).attr('data-id');
		var status=$(this).attr('data-status');
		var that=$(this)
		$.ajax({
			url:'/admin/change',
			data:{table:'mt_goods_struct',id:id,status:status},
			type:'get',
			success:function(res) {
				if(res.status==1){
					that.html(that.text() == '商品展示' ? '橱窗展示' : '商品展示')
					showMessage('操作成功~');
				}else{
					wxc.xcConfirm("操作失败,请重试","error");
				}
			}
		})	
	})

	$(".export-exl").click(function () {
		var id = $(this).attr("data-id")
		$.ajax({
			url: "/admin/product/struct_export",
			data: {id: id},
			success: function (res) {
				if (res.status == 1) {
					location = location.origin + "/" + res.pathname
				} else {
					var msg = res.msg || "导出文件失败!"
					window.wxc.xcConfirm(msg, "error")
				}
			}
		})
	})

	function xlsxUpload(e){
		var that=$(e);
		var file=e.files[0];
		var id = e.id
		var form = new FormData();
		form.append("file", file)
		form.append("id", id)
		$.ajax({
		  	url:"/admin/product/struct_import",
		  	data:form,
			type: "post",
		  	dataType: "json",
		  	cache: false,//上传文件无需缓存
		  	processData: false,//用于对data参数进行序列化处理 这里必须false
		  	contentType: false, //必须
		  	success:function(res){
		  		console.log(res)
		    	if (res.status==0) {
		      		window.wxc.xcConfirm("导入失败","error")
		    	}else{
		    		var msg = '导入时出错'
		   	    	msg += res.fail ? '\n有错误产品,请仔细检查: ' + res.fail : ''
		   	    	msg += res.has ? '\n已存在产品: '+ res.has : ''
		   	    	if (res.fail || res.has) {
		   	    		window.wxc.xcConfirm(msg,"warning")
		   	    		return
		   	    	} 
		   	    	window.wxc.xcConfirm('导入成功', "success")
		    	}
		  	}
		})
	}
</script>
</body>
</html>
